#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <stdlib.h>
using namespace std;
int main(){
    int N,M;
    scanf("%d %d",&N,&M);
    int **numbers;
    numbers=(int **)malloc(sizeof(int *)*N);
    for (int i=0; i<N; i++) numbers[i]=(int *)malloc(sizeof(int)*N);
    //printf("%d",N);
    //printf("%d",M);
        for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            scanf("%d", &numbers[i][j]);
            getchar(); // 消耗换行符
        }
    }

    for (int i = 0; i < M; i++) {
        string temp;
        scanf("%*s ", temp.c_str());
        
        getchar(); // 消耗换行符
        vector<int> operations;
        int operation = -1;

        if (temp=="insertVertex"){
            operation=0;
                    //printf("a");
        }
        if (temp=="insertEdge"){
            operation=1;
            int i,j,k;
            scanf("%d %d %d",&i,&j,&k);
            operations.push_back(i);
            operations.push_back(j);
            operations.push_back(k);
                    printf("b");
        }
        if (temp=="removeVertex"){
            operation=2;
            int i;
            scanf("%d",&i);
            operations.push_back(i);
                    //printf("c");
        }
        if (temp=="removeEdge"){
            operation=3;
            int i,j;
            scanf("%d %d",&i,&j);
            operations.push_back(i);
            operations.push_back(j);
            //printf("d");
        }
        
        
        if (operation==0){
            int **temp;
            N++;
            temp=(int **)malloc(sizeof(int *)*N);
            for (int i=0; i<N; i++) temp[i]=(int *)malloc(sizeof(int)*N);
            for (int i=0; i<N; i++){
                if (i!=N-1)
                for (int j=0;j<N;j++){
                    if (j!=N-1)temp[i][j]=numbers[i][j];
                    else temp[i][j]=0;
                }
                else{
                    for (int j=0;j<N;j++){
                        temp[i][j]=0;
                    }
                }
            }
            for (int i=0; i<N-1; i++) free(numbers[i]);
            free(numbers);
            numbers=temp;

        }
        //if (operation==1)printf("%d\n",N);
        if (operation==1){
            numbers[operations[0]-1][operations[1]-1]=operations[2];
            numbers[operations[1]-1][operations[0]-1]=operations[2];
        }
        if (operation==2){
            int **temp;
            N--;
            temp=(int **)malloc(sizeof(int *)*N);
            for (int i=0; i<N; i++) temp[i]=(int *)malloc(sizeof(int)*N);
            int v=operations[0];

            for (int i=0; i<v-1; i++){
                
                
                for (int j=0;j<v-1;j++){
                    temp[i][j]=numbers[i][j];
                }
                for (int j=v;j<N+1;j++){
                    temp[i][j-1]=numbers[i][j];
                }
            }
            for (int i=v; i<N+1; i++){
                
                for (int j=0;j<v; j++){
                    temp[i-1][j]=numbers[i][j];
                }
                for (int j=v;j<N+1;j++){
                    temp[i-1][j-1]=numbers[i][j];
                }
            }
            for (int i=0; i<N-1; i++) free(numbers[i]);
            free(numbers);
            numbers=temp;
        }
        if (operation==3){
            numbers[operations[0]-1][operations[1]-1]=0;
            numbers[operations[1]-1][operations[0]-1]=0;
        }
        //printf("%d\n",N);

    }
    for (int i=0; i<N; i++){
        for (int j=0; j<N; j++){
            printf("%d",numbers[i][j]);
            if (j!=N-1)printf(" ");
        }
        printf("\n");
    }
    

    return 0;
}
